<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use backend\utils\XHtml;

/* @var $this yii\web\View */
/* @var $val common\models\Config */

$this->title = '自定义设置';
$this->params['breadcrumbs'][] = ['label' => '自定义设置', 'url' => ['custom']];
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('content-header'); ?>
<?= $this->title . ' ' . XHtml::create('自定义', ['custom-create']) ?>
<?php $this->endBlock(); ?>
<div class="page-create">
    <div class="box box-primary">
        <div class="box-body">

            <?= $this->render('/site/error-summary', ['model' => $model]) ?>

            <?php $form = ActiveForm::begin(['options' => ['class' => 'form-horizontal']]); ?>

            <?php if ($config) {
                foreach ((array)$config as $val) { ?>
                    <div class="form-group">
                        <label class="col-lg-2 control-label"><?= $val->name ?></label>
                        <div class="col-lg-8">
                            <?php if($val->type=='file'){?>
                                <?php if ($val->value) { ?>
                                    <?= Html::img(Yii::getAlias('@frontendUrl') . $val->value, ['width' => '50']) ?>
                                <?php } ?>
                            <?php }else{?>
                            <?= XHtml::createByConfig($val->variable, $val->value, $val->type, $val->type_data ? json_decode($val->variable) : []) ?>
                            <?php }?>
                        </div>
                        <div class="col-lg-2">
                            <?= Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['custom-update', 'id' => $val->id]) ?>
                            &nbsp;&nbsp;
                            <?= Html::a('<span class="glyphicon glyphicon-trash"></span>', ['custom-delete', 'id' => $val->id], ['data-confirm' => '您确定要删除此项吗？']) ?>
                        </div>
                    </div>
                <?php }
            } else { ?>
                <?= Html::tag('h3', '还没有添加自定义设置', ['class' => 'text-center']) ?>
            <?php } ?>

            <div class="form-group">
                <label class="col-sm-2 control-label"></label>
                <?= XHtml::submitButton('保存') ?>&nbsp;&nbsp;
                <?= XHtml::resetButton() ?>
            </div>
            <?php ActiveForm::end(); ?>
        </div>
    </div>
</div>